<template>
  <div class="header_container">
    <h3 class="header_title">东软网易电商运营平台</h3>
    <i @click="handleCollapse" class="header_icon el-icon-menu"></i>
    <el-dropdown class="header_dropdown" @command="dropdwonFn">
      <span class="el-dropdown-link">
        {{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="home">首页</el-dropdown-item>
        <el-dropdown-item command="logout">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import { LOGOUT, UPDATECOLLAPSE } from "@/store/mutation-types";
export default {
  data() {
    return {
      flag: false
    };
  },
  computed: {
    username() {
      return this.$store.state.user.userinfo.username;
    },
  },
  methods: {
    handleCollapse() {
      if (!this.flag) {
        this.$store.commit(UPDATECOLLAPSE, !this.$store.state.user.collapse);
        this.flag = true;
        setTimeout(() => {
          this.flag = false;
        }, 400);
      }
      
    },
    dropdwonFn(c) {
      if (c == "home") {
        this.$router.push("/homepage");
      } else if (c == "logout") {
        // 清除token
        localStorage.clear();
        this.$store.commit(LOGOUT);
        this.$router.push("/login");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.header_container {
  height: 70px;
  background-color: #409eff;
  .header_title {
    display: inline-block;
    padding: 0 20px;
    line-height: 70px;
    font-weight: normal;
    font-size: 24px;
    color: #fff;
  }
  .header_icon {
    display: inline-block;
    line-height: 70px;
    color: #fff;
    font-size: 20px;
  }
  .header_dropdown {
    float: right;
    margin-top: 25px;
    margin-right: 20px;
    color: #fff;
  }
}
</style>